1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435
|
/*
* dLeyna
*
* Copyright (C) 2012-2017 Intel Corporation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU Lesser General Public License,
* version 2.1, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
*
* Mark Ryan <mark.d.ryan@intel.com>
* Regis Merlino <regis.merlino@intel.com>
*
*/
#include <config.h>
#include <glib.h>
#include <string.h>
#include <libdleyna/core/connector.h>
#include <libdleyna/core/context-filter.h>
#include <libdleyna/core/control-point.h>
#include <libdleyna/core/error.h>
#include <libdleyna/core/log.h>
#include <libdleyna/core/task-processor.h>
#include "async.h"
#include "client.h"
#include "control-point-server.h"
#include "device.h"
#include "interface.h"
#include "manager.h"
#include "path.h"
#include "server.h"
#include "upnp.h"
#ifdef UA_PREFIX
#define DLS_PRG_NAME UA_PREFIX " dLeyna/" VERSION
#else
#define DLS_PRG_NAME "dLeyna/" VERSION
#endif
typedef struct dls_server_context_t_ dls_server_context_t;
struct dls_server_context_t_ {
dleyna_connector_id_t connection;
dleyna_task_processor_t *processor;
const dleyna_connector_t *connector;
dleyna_settings_t *settings;
guint dls_id[DLS_MANAGER_INTERFACE_INFO_MAX];
GHashTable *watchers;
dls_upnp_t *upnp;
dls_manager_t *manager;
};
static dls_server_context_t g_context;
static const gchar g_root_introspection[] =
"<node>"
" <interface name='"DLEYNA_SERVER_INTERFACE_MANAGER"'>"
" <method name='"DLS_INTERFACE_GET_VERSION"'>"
" <arg type='s' name='"DLS_INTERFACE_VERSION"'"
" direction='out'/>"
" </method>"
" <method name='"DLS_INTERFACE_RELEASE"'>"
" </method>"
" <method name='"DLS_INTERFACE_GET_SERVERS"'>"
" <arg type='ao' name='"DLS_INTERFACE_SERVERS"'"
" direction='out'/>"
" </method>"
" <method name='"DLS_INTERFACE_RESCAN"'>"
" </method>"
" <method name='"DLS_INTERFACE_SET_PROTOCOL_INFO"'>"
" <arg type='s' name='"DLS_INTERFACE_PROTOCOL_INFO"'"
" direction='in'/>"
" </method>"
" <method name='"DLS_INTERFACE_PREFER_LOCAL_ADDRESSES"'>"
" <arg type='b' name='"DLS_INTERFACE_PREFER"'"
" direction='in'/>"
" </method>"
" <signal name='"DLS_INTERFACE_FOUND_SERVER"'>"
" <arg type='o' name='"DLS_INTERFACE_PATH"'/>"
" </signal>"
" <signal name='"DLS_INTERFACE_LOST_SERVER"'>"
" <arg type='o' name='"DLS_INTERFACE_PATH"'/>"
" </signal>"
" <property type='as' name='"DLS_INTERFACE_PROP_NEVER_QUIT"'"
" access='readwrite'/>"
" <property type='as' name='"DLS_INTERFACE_PROP_WHITE_LIST_ENTRIES"'"
" access='readwrite'/>"
" <property type='b' name='"DLS_INTERFACE_PROP_WHITE_LIST_ENABLED"'"
" access='readwrite'/>"
" </interface>"
" <interface name='"DLS_INTERFACE_PROPERTIES"'>"
" <method name='"DLS_INTERFACE_GET"'>"
" <arg type='s' name='"DLS_INTERFACE_INTERFACE_NAME"'"
" direction='in'/>"
" <arg type='s' name='"DLS_INTERFACE_PROPERTY_NAME"'"
" direction='in'/>"
" <arg type='v' name='"DLS_INTERFACE_VALUE"'"
" direction='out'/>"
" </method>"
" <method name='"DLS_INTERFACE_GET_ALL"'>"
" <arg type='s' name='"DLS_INTERFACE_INTERFACE_NAME"'"
" direction='in'/>"
" <arg type='a{sv}' name='"DLS_INTERFACE_PROPERTIES_VALUE"'"
" direction='out'/>"
" </method>"
" <method name='"DLS_INTERFACE_SET"'>"
" <arg type='s' name='"DLS_INTERFACE_INTERFACE_NAME"'"
" direction='in'/>"
" <arg type='s' name='"DLS_INTERFACE_PROPERTY_NAME"'"
" direction='in'/>"
" <arg type='v' name='"DLS_INTERFACE_VALUE"'"
" direction='in'/>"
" </method>"
" <signal name='"DLS_INTERFACE_PROPERTIES_CHANGED"'>"
" <arg type='s' name='"DLS_INTERFACE_INTERFACE_NAME"'/>"
" <arg type='a{sv}' name='"DLS_INTERFACE_CHANGED_PROPERTIES"'/>"
" <arg type='as' name='"
DLS_INTERFACE_INVALIDATED_PROPERTIES"'/>"
" </signal>"
" </interface>"
"</node>";
static const gchar g_server_introspection[] =
"<node>"
" <interface name='"DLS_INTERFACE_PROPERTIES"'>"
" <method name='"DLS_INTERFACE_GET"'>"
" <arg type='s' name='"DLS_INTERFACE_INTERFACE_NAME"'"
" direction='in'/>"
" <arg type='s' name='"DLS_INTERFACE_PROPERTY_NAME"'"
" direction='in'/>"
" <arg type='v' name='"DLS_INTERFACE_VALUE"'"
" direction='out'/>"
" </method>"
" <method name='"DLS_INTERFACE_GET_ALL"'>"
" <arg type='s' name='"DLS_INTERFACE_INTERFACE_NAME"'"
" direction='in'/>"
" <arg type='a{sv}' name='"DLS_INTERFACE_PROPERTIES_VALUE"'"
" direction='out'/>"
" </method>"
" <signal name='"DLS_INTERFACE_PROPERTIES_CHANGED"'>"
" <arg type='s' name='"DLS_INTERFACE_INTERFACE_NAME"'/>"
" <arg type='a{sv}' name='"DLS_INTERFACE_CHANGED_PROPERTIES"'/>"
" <arg type='as' name='"DLS_INTERFACE_INVALIDATED_PROPERTIES"'/>"
" </signal>"
" </interface>"
" <interface name='"DLS_INTERFACE_MEDIA_OBJECT"'>"
" <property type='o' name='"DLS_INTERFACE_PROP_PARENT"'"
" access='read'/>"
" <property type='s' name='"DLS_INTERFACE_PROP_TYPE"'"
" access='read'/>"
" <property type='s' name='"DLS_INTERFACE_PROP_TYPE_EX"'"
" access='read'/>"
" <property type='o' name='"DLS_INTERFACE_PROP_PATH"'"
" access='read'/>"
" <property type='s' name='"DLS_INTERFACE_PROP_DISPLAY_NAME"'"
" access='read'/>"
" <property type='s' name='"DLS_INTERFACE_PROP_CREATOR"'"
" access='read'/>"
" <property type='b' name='"DLS_INTERFACE_PROP_RESTRICTED"'"
" access='read'/>"
" <property type='a{sb}' name='"DLS_INTERFACE_PROP_DLNA_MANAGED"'"
" access='read'/>"
" <property type='u' name='"DLS_INTERFACE_PROP_OBJECT_UPDATE_ID"'"
" access='read'/>"
" <method name='"DLS_INTERFACE_DELETE"'>"
" </method>"
" <method name='"DLS_INTERFACE_UPDATE"'>"
" <arg type='a{sv}' name='"DLS_INTERFACE_TO_ADD_UPDATE"'"
" direction='in'/>"
" <arg type='as' name='"DLS_INTERFACE_TO_DELETE"'"
" direction='in'/>"
" </method>"
" <method name='"DLS_INTERFACE_GET_METADATA"'>"
" <arg type='s' name='"DLS_INTERFACE_METADATA"'"
" direction='out'/>"
" </method>"
" </interface>"
" <interface name='"DLS_INTERFACE_MEDIA_CONTAINER"'>"
" <method name='"DLS_INTERFACE_LIST_CHILDREN"'>"
" <arg type='u' name='"DLS_INTERFACE_OFFSET"'"
" direction='in'/>"
" <arg type='u' name='"DLS_INTERFACE_MAX"'"
" direction='in'/>"
" <arg type='as' name='"DLS_INTERFACE_FILTER"'"
" direction='in'/>"
" <arg type='aa{sv}' name='"DLS_INTERFACE_CHILDREN"'"
" direction='out'/>"
" </method>"
" <method name='"DLS_INTERFACE_LIST_CHILDREN_EX"'>"
" <arg type='u' name='"DLS_INTERFACE_OFFSET"'"
" direction='in'/>"
" <arg type='u' name='"DLS_INTERFACE_MAX"'"
" direction='in'/>"
" <arg type='as' name='"DLS_INTERFACE_FILTER"'"
" direction='in'/>"
" <arg type='s' name='"DLS_INTERFACE_SORT_BY"'"
" direction='in'/>"
" <arg type='aa{sv}' name='"DLS_INTERFACE_CHILDREN"'"
" direction='out'/>"
" </method>"
" <method name='"DLS_INTERFACE_LIST_CONTAINERS"'>"
" <arg type='u' name='"DLS_INTERFACE_OFFSET"'"
" direction='in'/>"
" <arg type='u' name='"DLS_INTERFACE_MAX"'"
" direction='in'/>"
" <arg type='as' name='"DLS_INTERFACE_FILTER"'"
" direction='in'/>"
" <arg type='aa{sv}' name='"DLS_INTERFACE_CHILDREN"'"
" direction='out'/>"
" </method>"
" <method name='"DLS_INTERFACE_LIST_CONTAINERS_EX"'>"
" <arg type='u' name='"DLS_INTERFACE_OFFSET"'"
" direction='in'/>"
" <arg type='u' name='"DLS_INTERFACE_MAX"'"
" direction='in'/>"
" <arg type='as' name='"DLS_INTERFACE_FILTER"'"
" direction='in'/>"
" <arg type='s' name='"DLS_INTERFACE_SORT_BY"'"
" direction='in'/>"
" <arg type='aa{sv}' name='"DLS_INTERFACE_CHILDREN"'"
" direction='out'/>"
" </method>"
" <method name='"DLS_INTERFACE_LIST_ITEMS"'>"
" <arg type='u' name='"DLS_INTERFACE_OFFSET"'"
" direction='in'/>"
" <arg type='u' name='"DLS_INTERFACE_MAX"'"
" direction='in'/>"
" <arg type='as' name='"DLS_INTERFACE_FILTER"'"
" direction='in'/>"
" <arg type='aa{sv}' name='"DLS_INTERFACE_CHILDREN"'"
" direction='out'/>"
" </method>"
" <method name='"DLS_INTERFACE_LIST_ITEMS_EX"'>"
" <arg type='u' name='"DLS_INTERFACE_OFFSET"'"
" direction='in'/>"
" <arg type='u' name='"DLS_INTERFACE_MAX"'"
" direction='in'/>"
" <arg type='as' name='"DLS_INTERFACE_FILTER"'"
" direction='in'/>"
" <arg type='s' name='"DLS_INTERFACE_SORT_BY"'"
" direction='in'/>"
" <arg type='aa{sv}' name='"DLS_INTERFACE_CHILDREN"'"
" direction='out'/>"
" </method>"
" <method name='"DLS_INTERFACE_SEARCH_OBJECTS"'>"
" <arg type='s' name='"DLS_INTERFACE_QUERY"'"
" direction='in'/>"
" <arg type='u' name='"DLS_INTERFACE_OFFSET"'"
" direction='in'/>"
" <arg type='u' name='"DLS_INTERFACE_MAX"'"
" direction='in'/>"
" <arg type='as' name='"DLS_INTERFACE_FILTER"'"
" direction='in'/>"
" <arg type='aa{sv}' name='"DLS_INTERFACE_CHILDREN"'"
" direction='out'/>"
" </method>"
" <method name='"DLS_INTERFACE_SEARCH_OBJECTS_EX"'>"
" <arg type='s' name='"DLS_INTERFACE_QUERY"'"
" direction='in'/>"
" <arg type='u' name='"DLS_INTERFACE_OFFSET"'"
" direction='in'/>"
" <arg type='u' name='"DLS_INTERFACE_MAX"'"
" direction='in'/>"
" <arg type='as' name='"DLS_INTERFACE_FILTER"'"
" direction='in'/>"
" <arg type='s' name='"DLS_INTERFACE_SORT_BY"'"
" direction='in'/>"
" <arg type='aa{sv}' name='"DLS_INTERFACE_CHILDREN"'"
" direction='out'/>"
" <arg type='u' name='"DLS_INTERFACE_TOTAL_ITEMS"'"
" direction='out'/>"
" </method>"
" <method name='"DLS_INTERFACE_UPLOAD"'>"
" <arg type='s' name='"DLS_INTERFACE_PROP_DISPLAY_NAME"'"
" direction='in'/>"
" <arg type='s' name='"DLS_INTERFACE_FILE_PATH"'"
" direction='in'/>"
" <arg type='u' name='"DLS_INTERFACE_UPLOAD_ID"'"
" direction='out'/>"
" <arg type='o' name='"DLS_INTERFACE_PATH"'"
" direction='out'/>"
" </method>"
" <method name='"DLS_INTERFACE_CREATE_CONTAINER"'>"
" <arg type='s' name='"DLS_INTERFACE_PROP_DISPLAY_NAME"'"
" direction='in'/>"
" <arg type='s' name='"DLS_INTERFACE_PROP_TYPE"'"
" direction='in'/>"
" <arg type='as' name='"DLS_INTERFACE_CHILD_TYPES"'"
" direction='in'/>"
" <arg type='o' name='"DLS_INTERFACE_PATH"'"
" direction='out'/>"
" </method>"
" <method name='"DLS_INTERFACE_GET_COMPATIBLE_RESOURCE"'>"
" <arg type='s' name='"DLS_INTERFACE_PROTOCOL_INFO"'"
" direction='in'/>"
" <arg type='as' name='"DLS_INTERFACE_FILTER"'"
" direction='in'/>"
" <arg type='a{sv}' name='"DLS_INTERFACE_PROPERTIES_VALUE"'"
" direction='out'/>"
" </method>"
" <method name='"DLS_INTERFACE_CREATE_REFERENCE"'>"
" <arg type='o' name='"DLS_INTERFACE_PATH"'"
" direction='in'/>"
" <arg type='o' name='"DLS_INTERFACE_REFPATH"'"
" direction='out'/>"
" </method>"
" <property type='u' name='"DLS_INTERFACE_PROP_CHILD_COUNT"'"
" access='read'/>"
" <property type='b' name='"DLS_INTERFACE_PROP_SEARCHABLE"'"
" access='read'/>"
" <property type='a(sb)' name='"DLS_INTERFACE_PROP_CREATE_CLASSES"'"
" access='read'/>"
" <property type='u' name='"DLS_INTERFACE_PROP_CONTAINER_UPDATE_ID"'"
" access='read'/>"
" <property type='u' name='"
DLS_INTERFACE_PROP_TOTAL_DELETED_CHILD_COUNT"'"
" access='read'/>"
" <property type='aa{sv}' name='"DLS_INTERFACE_PROP_RESOURCES"'"
" access='read'/>"
" <property type='as' name='"DLS_INTERFACE_PROP_URLS"'"
" access='read'/>"
" <property type='s' name='"DLS_INTERFACE_PROP_MIME_TYPE"'"
" access='read'/>"
" <property type='s' name='"DLS_INTERFACE_PROP_DLNA_PROFILE"'"
" access='read'/>"
" <property type='a{sb}' name='"DLS_INTERFACE_PROP_DLNA_CONVERSION"'"
" access='read'/>"
" <property type='a{sb}' name='"DLS_INTERFACE_PROP_DLNA_OPERATION"'"
" access='read'/>"
" <property type='a{sb}' name='"DLS_INTERFACE_PROP_DLNA_FLAGS"'"
" access='read'/>"
" <property type='x' name='"DLS_INTERFACE_PROP_SIZE"'"
" access='read'/>"
" <property type='s' name='"DLS_INTERFACE_PROP_ARTIST"'"
" access='read'/>"
" <property type='s' name='"DLS_INTERFACE_PROP_ALBUM_ART_URL"'"
" access='read'/>"
" </interface>"
" <interface name='"DLS_INTERFACE_MEDIA_ITEM"'>"
" <method name='"DLS_INTERFACE_GET_COMPATIBLE_RESOURCE"'>"
" <arg type='s' name='"DLS_INTERFACE_PROTOCOL_INFO"'"
" direction='in'/>"
" <arg type='as' name='"DLS_INTERFACE_FILTER"'"
" direction='in'/>"
" <arg type='a{sv}' name='"DLS_INTERFACE_PROPERTIES_VALUE"'"
" direction='out'/>"
" </method>"
" <property type='as' name='"DLS_INTERFACE_PROP_URLS"'"
" access='read'/>"
" <property type='s' name='"DLS_INTERFACE_PROP_MIME_TYPE"'"
" access='read'/>"
" <property type='s' name='"DLS_INTERFACE_PROP_ARTIST"'"
" access='read'/>"
" <property type='as' name='"DLS_INTERFACE_PROP_ARTISTS"'"
" access='read'/>"
" <property type='s' name='"DLS_INTERFACE_PROP_ALBUM"'"
" access='read'/>"
" <property type='s' name='"DLS_INTERFACE_PROP_DATE"'"
" access='read'/>"
" <property type='s' name='"DLS_INTERFACE_PROP_GENRE"'"
" access='read'/>"
" <property type='s' name='"DLS_INTERFACE_PROP_DLNA_PROFILE"'"
" access='read'/>"
" <property type='a{sb}' name='"DLS_INTERFACE_PROP_DLNA_CONVERSION"'"
" access='read'/>"
" <property type='a{sb}' name='"DLS_INTERFACE_PROP_DLNA_OPERATION"'"
" access='read'/>"
" <property type='a{sb}' name='"DLS_INTERFACE_PROP_DLNA_FLAGS"'"
" access='read'/>"
" <property type='i' name='"DLS_INTERFACE_PROP_TRACK_NUMBER"'"
" access='read'/>"
" <property type='x' name='"DLS_INTERFACE_PROP_SIZE"'"
" access='read'/>"
" <property type='i' name='"DLS_INTERFACE_PROP_DURATION"'"
" access='read'/>"
" <property type='i' name='"DLS_INTERFACE_PROP_BITRATE"'"
" access='read'/>"
" <property type='i' name='"DLS_INTERFACE_PROP_SAMPLE_RATE"'"
" access='read'/>"
" <property type='i' name='"DLS_INTERFACE_PROP_BITS_PER_SAMPLE"'"
" access='read'/>"
" <property type='i' name='"DLS_INTERFACE_PROP_WIDTH"'"
" access='read'/>"
" <property type='i' name='"DLS_INTERFACE_PROP_HEIGHT"'"
" access='read'/>"
" <property type='i' name='"DLS_INTERFACE_PROP_COLOR_DEPTH"'"
" access='read'/>"
" <property type='s' name='"DLS_INTERFACE_PROP_ALBUM_ART_URL"'"
" access='read'/>"
" <property type='o' name='"DLS_INTERFACE_PROP_REFPATH"'"
" access='read'/>"
" <property type='aa{sv}' name='"DLS_INTERFACE_PROP_RESOURCES"'"
" access='read'/>"
" </interface>"
" <interface name='"DLEYNA_SERVER_INTERFACE_MEDIA_DEVICE"'>"
" <method name='"DLS_INTERFACE_UPLOAD_TO_ANY"'>"
" <arg type='s' name='"DLS_INTERFACE_PROP_DISPLAY_NAME"'"
" direction='in'/>"
" <arg type='s' name='"DLS_INTERFACE_FILE_PATH"'"
" direction='in'/>"
" <arg type='u' name='"DLS_INTERFACE_UPLOAD_ID"'"
" direction='out'/>"
" <arg type='o' name='"DLS_INTERFACE_PATH"'"
" direction='out'/>"
" </method>"
" <method name='"DLS_INTERFACE_GET_UPLOAD_STATUS"'>"
" <arg type='u' name='"DLS_INTERFACE_UPLOAD_ID"'"
" direction='in'/>"
" <arg type='s' name='"DLS_INTERFACE_UPLOAD_STATUS"'"
" direction='out'/>"
" <arg type='t' name='"DLS_INTERFACE_LENGTH"'"
" direction='out'/>"
" <arg type='t' name='"DLS_INTERFACE_TOTAL"'"
" direction='out'/>"
" </method>"
" <method name='"DLS_INTERFACE_GET_UPLOAD_IDS"'>"
" <arg type='au' name='"DLS_INTERFACE_TOTAL"'"
" direction='out'/>"
" </method>"
" <method name='"DLS_INTERFACE_CANCEL_UPLOAD"'>"
" <arg type='u' name='"DLS_INTERFACE_UPLOAD_ID"'"
" direction='in'/>"
" </method>"
" <method name='"DLS_INTERFACE_CREATE_CONTAINER_IN_ANY"'>"
" <arg type='s' name='"DLS_INTERFACE_PROP_DISPLAY_NAME"'"
" direction='in'/>"
" <arg type='s' name='"DLS_INTERFACE_PROP_TYPE"'"
" direction='in'/>"
" <arg type='as' name='"DLS_INTERFACE_CHILD_TYPES"'"
" direction='in'/>"
" <arg type='o' name='"DLS_INTERFACE_PATH"'"
" direction='out'/>"
" </method>"
" <method name='"DLS_INTERFACE_CANCEL"'>"
" </method>"
" <method name='"DLS_INTERFACE_WAKE"'>"
" </method>"
" <method name='"DLS_INTERFACE_GET_ICON"'>"
" <arg type='s' name='"DLS_INTERFACE_REQ_MIME_TYPE"'"
" direction='in'/>"
" <arg type='s' name='"DLS_INTERFACE_RESOLUTION"'"
" direction='in'/>"
" <arg type='ay' name='"DLS_INTERFACE_ICON_BYTES"'"
" direction='out'/>"
" <arg type='s' name='"DLS_INTERFACE_MIME_TYPE"'"
" direction='out'/>"
" </method>"
" <method name='"DLS_INTERFACE_BROWSE_OBJECTS"'>"
" <arg type='ao' name='"DLS_INTERFACE_OBJECTS_PATH"'"
" direction='in'/>"
" <arg type='as' name='"DLS_INTERFACE_FILTER"'"
" direction='in'/>"
" <arg type='aa{sv}' name='"DLS_INTERFACE_CHILDREN"'"
" direction='out'/>"
" </method>"
" <property type='s' name='"DLS_INTERFACE_PROP_LOCATION"'"
" access='read'/>"
" <property type='s' name='"DLS_INTERFACE_PROP_UDN"'"
" access='read'/>"
" <property type='s' name='"DLS_INTERFACE_PROP_DEVICE_TYPE"'"
" access='read'/>"
" <property type='s' name='"DLS_INTERFACE_PROP_FRIENDLY_NAME"'"
" access='read'/>"
" <property type='s' name='"DLS_INTERFACE_PROP_MANUFACTURER"'"
" access='read'/>"
" <property type='s' name='"DLS_INTERFACE_PROP_MANUFACTURER_URL"'"
" access='read'/>"
" <property type='s' name='"DLS_INTERFACE_PROP_MODEL_DESCRIPTION"'"
" access='read'/>"
" <property type='s' name='"DLS_INTERFACE_PROP_MODEL_NAME"'"
" access='read'/>"
" <property type='s' name='"DLS_INTERFACE_PROP_MODEL_NUMBER"'"
" access='read'/>"
" <property type='s' name='"DLS_INTERFACE_PROP_MODEL_URL"'"
" access='read'/>"
" <property type='s' name='"DLS_INTERFACE_PROP_SERIAL_NUMBER"'"
" access='read'/>"
" <property type='s' name='"DLS_INTERFACE_PROP_PRESENTATION_URL"'"
" access='read'/>"
" <property type='s' name='"DLS_INTERFACE_PROP_ICON_URL"'"
" access='read'/>"
" <property type='b' name='"DLS_INTERFACE_PROP_SLEEPING"'"
" access='read'/>"
" <property type='a{sv}'name='"
DLS_INTERFACE_PROP_SV_DLNA_CAPABILITIES"'"
" access='read'/>"
" <property type='as' name='"
DLS_INTERFACE_PROP_SV_SEARCH_CAPABILITIES"'"
" access='read'/>"
" <property type='as' name='"
DLS_INTERFACE_PROP_SV_SORT_CAPABILITIES"'"
" access='read'/>"
" <property type='as' name='"
DLS_INTERFACE_PROP_SV_SORT_EXT_CAPABILITIES"'"
" access='read'/>"
" <property type='a(ssao)' name='"
DLS_INTERFACE_PROP_SV_FEATURE_LIST"'"
" access='read'/>"
" <property type='u' name='"
DLS_INTERFACE_PROP_ESV_SYSTEM_UPDATE_ID"'"
" access='read'/>"
" <property type='s' name='"
DLS_INTERFACE_PROP_SV_SERVICE_RESET_TOKEN"'"
" access='read'/>"
" <signal name='"DLS_INTERFACE_ESV_CONTAINER_UPDATE_IDS"'>"
" <arg type='a(ou)' name='"DLS_INTERFACE_CONTAINER_PATHS_ID"'/>"
" </signal>"
" <signal name='"DLS_INTERFACE_CHANGED_EVENT"'>"
" <arg type='aa{sv}' name='"DLS_INTERFACE_CHANGED_OBJECTS"'/>"
" </signal>"
" <signal name='"DLS_INTERFACE_UPLOAD_UPDATE"'>"
" <arg type='u' name='"DLS_INTERFACE_UPLOAD_ID"'/>"
" <arg type='s' name='"DLS_INTERFACE_UPLOAD_STATUS"'/>"
" <arg type='t' name='"DLS_INTERFACE_LENGTH"'/>"
" <arg type='t' name='"DLS_INTERFACE_TOTAL"'/>"
" </signal>"
" </interface>"
"</node>";
static const gchar *g_manager_interfaces[DLS_MANAGER_INTERFACE_INFO_MAX] = {
/* MUST be in the exact same order as g_root_introspection */
DLEYNA_SERVER_INTERFACE_MANAGER,
DLS_INTERFACE_PROPERTIES
};
const dleyna_connector_t *dls_server_get_connector(void)
{
return g_context.connector;
}
dleyna_task_processor_t *dls_server_get_task_processor(void)
{
return g_context.processor;
}
static void prv_process_sync_task(dls_task_t *task)
{
dls_client_t *client;
const gchar *client_name;
switch (task->type) {
case DLS_TASK_GET_VERSION:
task->result = g_variant_ref_sink(g_variant_new_string(
VERSION));
dls_task_complete(task);
break;
case DLS_TASK_GET_SERVERS:
task->result = dls_upnp_get_device_ids(g_context.upnp);
dls_task_complete(task);
break;
case DLS_TASK_RESCAN:
dls_upnp_rescan(g_context.upnp);
dls_task_complete(task);
break;
case DLS_TASK_SET_PROTOCOL_INFO:
client_name = dleyna_task_queue_get_source(task->atom.queue_id);
client = g_hash_table_lookup(g_context.watchers, client_name);
if (client) {
g_free(client->protocol_info);
if (task->ut.protocol_info.protocol_info[0]) {
client->protocol_info =
task->ut.protocol_info.protocol_info;
task->ut.protocol_info.protocol_info = NULL;
} else {
client->protocol_info = NULL;
}
}
dls_task_complete(task);
break;
case DLS_TASK_SET_PREFER_LOCAL_ADDRESSES:
client_name = dleyna_task_queue_get_source(task->atom.queue_id);
client = g_hash_table_lookup(g_context.watchers, client_name);
if (client) {
client->prefer_local_addresses =
task->ut.prefer_local_addresses.prefer;
}
dls_task_complete(task);
break;
case DLS_TASK_GET_UPLOAD_STATUS:
dls_upnp_get_upload_status(g_context.upnp, task);
break;
case DLS_TASK_GET_UPLOAD_IDS:
dls_upnp_get_upload_ids(g_context.upnp, task);
break;
case DLS_TASK_CANCEL_UPLOAD:
dls_upnp_cancel_upload(g_context.upnp, task);
break;
default:
goto finished;
break;
}
dleyna_task_queue_task_completed(task->atom.queue_id);
finished:
return;
}
static void prv_async_task_complete(dls_task_t *task, GError *error)
{
DLEYNA_LOG_DEBUG("Enter");
if (!error) {
dls_task_complete(task);
} else {
dls_task_fail(task, error);
g_error_free(error);
}
dleyna_task_queue_task_completed(task->atom.queue_id);
DLEYNA_LOG_DEBUG("Exit");
}
static void prv_process_async_task(dls_task_t *task)
{
dls_async_task_t *async_task = (dls_async_task_t *)task;
dls_client_t *client;
const gchar *client_name;
DLEYNA_LOG_DEBUG("Enter");
async_task->cancellable = g_cancellable_new();
client_name = dleyna_task_queue_get_source(task->atom.queue_id);
client = g_hash_table_lookup(g_context.watchers, client_name);
switch (task->type) {
case DLS_TASK_MANAGER_GET_PROP:
dls_manager_get_prop(g_context.manager, g_context.settings,
task, prv_async_task_complete);
break;
case DLS_TASK_MANAGER_GET_ALL_PROPS:
dls_manager_get_all_props(g_context.manager, g_context.settings,
task, prv_async_task_complete);
break;
case DLS_TASK_MANAGER_SET_PROP:
dls_manager_set_prop(g_context.manager, g_context.settings,
task, prv_async_task_complete);
break;
case DLS_TASK_GET_CHILDREN:
dls_upnp_get_children(g_context.upnp, client, task,
prv_async_task_complete);
break;
case DLS_TASK_GET_PROP:
dls_upnp_get_prop(g_context.upnp, client, task,
prv_async_task_complete);
break;
case DLS_TASK_GET_ALL_PROPS:
dls_upnp_get_all_props(g_context.upnp, client, task,
prv_async_task_complete);
break;
case DLS_TASK_SEARCH:
dls_upnp_search(g_context.upnp, client, task,
prv_async_task_complete);
break;
case DLS_TASK_BROWSE_OBJECTS:
dls_upnp_browse_objects(g_context.upnp, client, task,
prv_async_task_complete);
break;
case DLS_TASK_GET_RESOURCE:
dls_upnp_get_resource(g_context.upnp, client, task,
prv_async_task_complete);
break;
case DLS_TASK_UPLOAD_TO_ANY:
dls_upnp_upload_to_any(g_context.upnp, client, task,
prv_async_task_complete);
break;
case DLS_TASK_UPLOAD:
dls_upnp_upload(g_context.upnp, client, task,
prv_async_task_complete);
break;
case DLS_TASK_DELETE_OBJECT:
dls_upnp_delete_object(g_context.upnp, client, task,
prv_async_task_complete);
break;
case DLS_TASK_CREATE_CONTAINER:
dls_upnp_create_container(g_context.upnp, client, task,
prv_async_task_complete);
break;
case DLS_TASK_CREATE_CONTAINER_IN_ANY:
dls_upnp_create_container_in_any(g_context.upnp, client, task,
prv_async_task_complete);
break;
case DLS_TASK_UPDATE_OBJECT:
dls_upnp_update_object(g_context.upnp, client, task,
prv_async_task_complete);
break;
case DLS_TASK_GET_OBJECT_METADATA:
dls_upnp_get_object_metadata(g_context.upnp, client, task,
prv_async_task_complete);
break;
case DLS_TASK_CREATE_REFERENCE:
dls_upnp_create_reference(g_context.upnp, client, task,
prv_async_task_complete);
break;
case DLS_TASK_GET_ICON:
dls_upnp_get_icon(g_context.upnp, client, task,
prv_async_task_complete);
break;
case DLS_TASK_WAKE:
dls_upnp_wake(g_context.upnp, client, task,
prv_async_task_complete);
break;
default:
break;
}
DLEYNA_LOG_DEBUG("Exit");
}
static void prv_process_task(dleyna_task_atom_t *task, gpointer user_data)
{
dls_task_t *client_task = (dls_task_t *)task;
if (client_task->synchronous)
prv_process_sync_task(client_task);
else
prv_process_async_task(client_task);
}
static void prv_cancel_task(dleyna_task_atom_t *task, gpointer user_data)
{
dls_task_cancel((dls_task_t *)task);
}
static void prv_delete_task(dleyna_task_atom_t *task, gpointer user_data)
{
dls_task_delete((dls_task_t *)task);
}
static void prv_manager_root_method_call(dleyna_connector_id_t conn,
const gchar *sender,
const gchar *object,
const gchar *interface,
const gchar *method,
GVariant *parameters,
dleyna_connector_msg_id_t invocation);
static void prv_manager_props_method_call(dleyna_connector_id_t conn,
const gchar *sender,
const gchar *object,
const gchar *interface,
const gchar *method,
GVariant *parameters,
dleyna_connector_msg_id_t invocation);
static void prv_object_method_call(dleyna_connector_id_t conn,
const gchar *sender,
const gchar *object,
const gchar *interface,
const gchar *method,
GVariant *parameters,
dleyna_connector_msg_id_t invocation);
static void prv_item_method_call(dleyna_connector_id_t conn,
const gchar *sender,
const gchar *object,
const gchar *interface,
const gchar *method,
GVariant *parameters,
dleyna_connector_msg_id_t invocation);
static void prv_con_method_call(dleyna_connector_id_t conn,
const gchar *sender,
const gchar *object,
const gchar *interface,
const gchar *method,
GVariant *parameters,
dleyna_connector_msg_id_t invocation);
static void prv_props_method_call(dleyna_connector_id_t conn,
const gchar *sender,
const gchar *object,
const gchar *interface,
const gchar *method,
GVariant *parameters,
dleyna_connector_msg_id_t invocation);
static void prv_device_method_call(dleyna_connector_id_t conn,
const gchar *sender,
const gchar *object,
const gchar *interface,
const gchar *method,
GVariant *parameters,
dleyna_connector_msg_id_t invocation);
static const dleyna_connector_dispatch_cb_t
g_root_vtables[DLS_MANAGER_INTERFACE_INFO_MAX] = {
/* MUST be in the exact same order as g_root_introspection */
prv_manager_root_method_call,
prv_manager_props_method_call
};
static const dleyna_connector_dispatch_cb_t
g_server_vtables[DLS_INTERFACE_INFO_MAX] = {
/* MUST be in the exact same order as g_server_introspection */
prv_props_method_call,
prv_object_method_call,
prv_con_method_call,
prv_item_method_call,
prv_device_method_call
};
static void prv_remove_client(const gchar *name)
{
dleyna_task_processor_remove_queues_for_source(g_context.processor,
name);
(void) g_hash_table_remove(g_context.watchers, name);
if (g_hash_table_size(g_context.watchers) == 0)
if (!dleyna_settings_is_never_quit(g_context.settings))
dleyna_task_processor_set_quitting(g_context.processor);
}
static void prv_lost_client(const gchar *name)
{
DLEYNA_LOG_DEBUG("Lost Client %s", name);
prv_remove_client(name);
}
static void prv_add_task(dls_task_t *task, const gchar *source,
const gchar *sink)
{
dls_client_t *client;
const dleyna_task_queue_key_t *queue_id;
if (!g_hash_table_lookup(g_context.watchers, source)) {
client = g_new0(dls_client_t, 1);
client->prefer_local_addresses = TRUE;
g_context.connector->watch_client(source);
g_hash_table_insert(g_context.watchers, g_strdup(source),
client);
}
queue_id = dleyna_task_processor_lookup_queue(g_context.processor,
source, sink);
if (!queue_id)
queue_id = dleyna_task_processor_add_queue(
g_context.processor,
source,
sink,
DLEYNA_TASK_QUEUE_FLAG_AUTO_START,
prv_process_task,
prv_cancel_task,
prv_delete_task);
dleyna_task_queue_add_task(queue_id, &task->atom);
}
static void prv_manager_root_method_call(
dleyna_connector_id_t conn,
const gchar *sender, const gchar *object,
const gchar *interface,
const gchar *method, GVariant *parameters,
dleyna_connector_msg_id_t invocation)
{
dls_task_t *task;
if (!strcmp(method, DLS_INTERFACE_RELEASE)) {
prv_remove_client(sender);
g_context.connector->return_response(invocation, NULL);
goto finished;
} else if (!strcmp(method, DLS_INTERFACE_RESCAN)) {
task = dls_task_rescan_new(invocation);
} else if (!strcmp(method, DLS_INTERFACE_GET_VERSION)) {
task = dls_task_get_version_new(invocation);
} else if (!strcmp(method, DLS_INTERFACE_GET_SERVERS)) {
task = dls_task_get_servers_new(invocation);
} else if (!strcmp(method, DLS_INTERFACE_SET_PROTOCOL_INFO)) {
task = dls_task_set_protocol_info_new(invocation,
parameters);
} else if (!strcmp(method, DLS_INTERFACE_PREFER_LOCAL_ADDRESSES)) {
task = dls_task_prefer_local_addresses_new(invocation,
parameters);
} else {
goto finished;
}
prv_add_task(task, sender, DLS_SERVER_SINK);
finished:
return;
}
static void prv_manager_props_method_call(dleyna_connector_id_t conn,
const gchar *sender,
const gchar *object,
const gchar *interface,
const gchar *method,
GVariant *parameters,
dleyna_connector_msg_id_t invocation)
{
dls_task_t *task;
GError *error = NULL;
if (!strcmp(method, DLS_INTERFACE_GET_ALL))
task = dls_task_manager_get_props_new(invocation, object,
parameters, &error);
else if (!strcmp(method, DLS_INTERFACE_GET))
task = dls_task_manager_get_prop_new(invocation, object,
parameters, &error);
else if (!strcmp(method, DLS_INTERFACE_SET))
task = dls_task_manager_set_prop_new(invocation, object,
parameters, &error);
else
goto finished;
if (!task) {
g_context.connector->return_error(invocation, error);
g_error_free(error);
goto finished;
}
prv_add_task(task, sender, task->target.path);
finished:
return;
}
gboolean dls_server_get_object_info(const gchar *object_path,
gchar **root_path,
gchar **object_id,
dls_device_t **device,
GError **error)
{
if (!dls_path_get_path_and_id(object_path, root_path, object_id,
error)) {
DLEYNA_LOG_WARNING("Bad object %s", object_path);
goto on_error;
}
*device = dls_device_from_path(*root_path,
dls_upnp_get_device_udn_map(g_context.upnp));
if (*device == NULL) {
*device = dls_device_from_path(*root_path,
dls_upnp_get_sleeping_device_udn_map(
g_context.upnp));
}
if (*device == NULL) {
DLEYNA_LOG_WARNING("Cannot locate device for %s", *root_path);
*error = g_error_new(DLEYNA_SERVER_ERROR,
DLEYNA_ERROR_OBJECT_NOT_FOUND,
"Cannot locate device corresponding to"
" the specified path");
g_free(*root_path);
g_free(*object_id);
goto on_error;
}
return TRUE;
on_error:
return FALSE;
}
gboolean dls_server_is_device_sleeping(dls_device_t *dev)
{
if (dev->sleeping_context != NULL)
return TRUE;
else
return dev->sleeping;
}
void dls_server_delete_sleeping_device(dls_device_t *dev)
{
if (dev->sleeping_context != NULL)
dls_upnp_delete_sleeping_device(g_context.upnp, dev);
}
static const gchar *prv_get_device_id(const gchar *object, GError **error)
{
dls_device_t *device;
gchar *root_path;
gchar *id;
if (!dls_server_get_object_info(object, &root_path, &id, &device,
error))
goto on_error;
g_free(id);
g_free(root_path);
return device->path;
on_error:
return NULL;
}
static void prv_object_method_call(dleyna_connector_id_t conn,
const gchar *sender, const gchar *object,
const gchar *interface,
const gchar *method,
GVariant *parameters,
dleyna_connector_msg_id_t invocation)
{
dls_task_t *task;
GError *error = NULL;
if (!strcmp(method, DLS_INTERFACE_DELETE))
task = dls_task_delete_new(invocation, object, &error);
else if (!strcmp(method, DLS_INTERFACE_UPDATE))
task = dls_task_update_new(invocation, object,
parameters, &error);
else if (!strcmp(method, DLS_INTERFACE_GET_METADATA))
task = dls_task_get_metadata_new(invocation, object, &error);
else
goto finished;
if (!task) {
g_context.connector->return_error(invocation, error);
g_error_free(error);
goto finished;
}
prv_add_task(task, sender, task->target.device->path);
finished:
return;
}
static void prv_item_method_call(dleyna_connector_id_t conn,
const gchar *sender,
const gchar *object,
const gchar *interface,
const gchar *method,
GVariant *parameters,
dleyna_connector_msg_id_t invocation)
{
dls_task_t *task;
GError *error = NULL;
if (!strcmp(method, DLS_INTERFACE_GET_COMPATIBLE_RESOURCE)) {
task = dls_task_get_resource_new(invocation, object,
parameters, &error);
if (!task) {
g_context.connector->return_error(invocation, error);
g_error_free(error);
goto finished;
}
prv_add_task(task, sender, task->target.device->path);
}
finished:
return;
}
static void prv_con_method_call(dleyna_connector_id_t conn,
const gchar *sender,
const gchar *object,
const gchar *interface,
const gchar *method,
GVariant *parameters,
dleyna_connector_msg_id_t invocation)
{
dls_task_t *task;
GError *error = NULL;
if (!strcmp(method, DLS_INTERFACE_LIST_CHILDREN))
task = dls_task_get_children_new(invocation, object,
parameters, TRUE,
TRUE, &error);
else if (!strcmp(method, DLS_INTERFACE_LIST_CHILDREN_EX))
task = dls_task_get_children_ex_new(invocation, object,
parameters, TRUE,
TRUE, &error);
else if (!strcmp(method, DLS_INTERFACE_LIST_ITEMS))
task = dls_task_get_children_new(invocation, object,
parameters, TRUE,
FALSE, &error);
else if (!strcmp(method, DLS_INTERFACE_LIST_ITEMS_EX))
task = dls_task_get_children_ex_new(invocation, object,
parameters, TRUE,
FALSE, &error);
else if (!strcmp(method, DLS_INTERFACE_LIST_CONTAINERS))
task = dls_task_get_children_new(invocation, object,
parameters, FALSE,
TRUE, &error);
else if (!strcmp(method, DLS_INTERFACE_LIST_CONTAINERS_EX))
task = dls_task_get_children_ex_new(invocation, object,
parameters, FALSE,
TRUE, &error);
else if (!strcmp(method, DLS_INTERFACE_SEARCH_OBJECTS))
task = dls_task_search_new(invocation, object,
parameters, &error);
else if (!strcmp(method, DLS_INTERFACE_SEARCH_OBJECTS_EX))
task = dls_task_search_ex_new(invocation, object,
parameters, &error);
else if (!strcmp(method, DLS_INTERFACE_UPLOAD))
task = dls_task_upload_new(invocation, object,
parameters, &error);
else if (!strcmp(method, DLS_INTERFACE_CREATE_CONTAINER))
task = dls_task_create_container_new_generic(invocation,
DLS_TASK_CREATE_CONTAINER,
object, parameters, &error);
else if (!strcmp(method, DLS_INTERFACE_GET_COMPATIBLE_RESOURCE))
task = dls_task_get_resource_new(invocation, object,
parameters, &error);
else if (!strcmp(method, DLS_INTERFACE_CREATE_REFERENCE))
task = dls_task_create_reference_new(invocation,
DLS_TASK_CREATE_REFERENCE,
object, parameters, &error);
else
goto finished;
if (!task) {
g_context.connector->return_error(invocation, error);
g_error_free(error);
goto finished;
}
prv_add_task(task, sender, task->target.device->path);
finished:
return;
}
static void prv_props_method_call(dleyna_connector_id_t conn,
const gchar *sender,
const gchar *object,
const gchar *interface,
const gchar *method,
GVariant *parameters,
dleyna_connector_msg_id_t invocation)
{
dls_task_t *task;
GError *error = NULL;
if (!strcmp(method, DLS_INTERFACE_GET_ALL))
task = dls_task_get_props_new(invocation, object,
parameters, &error);
else if (!strcmp(method, DLS_INTERFACE_GET))
task = dls_task_get_prop_new(invocation, object,
parameters, &error);
else
goto finished;
if (!task) {
g_context.connector->return_error(invocation, error);
g_error_free(error);
goto finished;
}
prv_add_task(task, sender, task->target.device->path);
finished:
return;
}
static void prv_device_method_call(dleyna_connector_id_t conn,
const gchar *sender,
const gchar *object,
const gchar *interface,
const gchar *method,
GVariant *parameters,
dleyna_connector_msg_id_t invocation)
{
dls_task_t *task;
GError *error = NULL;
const gchar *device_id;
const dleyna_task_queue_key_t *queue_id;
if (!strcmp(method, DLS_INTERFACE_UPLOAD_TO_ANY)) {
task = dls_task_upload_to_any_new(invocation,
object, parameters, &error);
} else if (!strcmp(method, DLS_INTERFACE_CREATE_CONTAINER_IN_ANY)) {
task = dls_task_create_container_new_generic(
invocation,
DLS_TASK_CREATE_CONTAINER_IN_ANY,
object, parameters, &error);
} else if (!strcmp(method, DLS_INTERFACE_GET_UPLOAD_STATUS)) {
task = dls_task_get_upload_status_new(invocation,
object, parameters,
&error);
} else if (!strcmp(method, DLS_INTERFACE_GET_UPLOAD_IDS)) {
task = dls_task_get_upload_ids_new(invocation, object,
&error);
} else if (!strcmp(method, DLS_INTERFACE_CANCEL_UPLOAD)) {
task = dls_task_cancel_upload_new(invocation, object,
parameters, &error);
} else if (!strcmp(method, DLS_INTERFACE_GET_ICON)) {
task = dls_task_get_icon_new(invocation, object, parameters,
&error);
} else if (!strcmp(method, DLS_INTERFACE_BROWSE_OBJECTS)) {
task = dls_task_browse_objects_new(invocation, object,
parameters, &error);
} else if (!strcmp(method, DLS_INTERFACE_WAKE)) {
task = dls_task_wake_new(invocation, object, &error);
} else if (!strcmp(method, DLS_INTERFACE_CANCEL)) {
task = NULL;
device_id = prv_get_device_id(object, &error);
if (!device_id)
goto on_error;
queue_id = dleyna_task_processor_lookup_queue(
g_context.processor,
sender,
device_id);
if (queue_id)
dleyna_task_processor_cancel_queue(queue_id);
g_context.connector->return_response(invocation, NULL);
goto finished;
} else {
goto finished;
}
on_error:
if (!task) {
g_context.connector->return_error(invocation, error);
g_error_free(error);
goto finished;
}
prv_add_task(task, sender, task->target.device->path);
finished:
return;
}
static void prv_found_media_server(const gchar *path, void *user_data)
{
(void) g_context.connector->notify(g_context.connection,
DLEYNA_SERVER_OBJECT,
DLEYNA_SERVER_INTERFACE_MANAGER,
DLS_INTERFACE_FOUND_SERVER,
g_variant_new("(o)", path),
NULL);
}
static void prv_lost_media_server(const gchar *path, void *user_data)
{
(void) g_context.connector->notify(g_context.connection,
DLEYNA_SERVER_OBJECT,
DLEYNA_SERVER_INTERFACE_MANAGER,
DLS_INTERFACE_LOST_SERVER,
g_variant_new("(o)", path),
NULL);
dleyna_task_processor_remove_queues_for_sink(g_context.processor, path);
}
static void prv_unregister_client(gpointer user_data)
{
dls_client_t *client = user_data;
if (client) {
g_free(client->protocol_info);
g_free(client);
}
}
dls_upnp_t *dls_server_get_upnp(void)
{
return g_context.upnp;
}
static void prv_context_filter_init(void)
{
gboolean enabled;
GVariant *entries;
dleyna_context_filter_t *wl;
DLEYNA_LOG_DEBUG("Enter");
enabled = dleyna_settings_is_context_filter_enabled(g_context.settings);
entries = dleyna_settings_context_filter_entries(g_context.settings);
wl = dls_manager_get_context_filter(g_context.manager);
dleyna_context_filter_enable(wl, enabled);
dleyna_context_filter_add_entries(wl, entries);
DLEYNA_LOG_DEBUG("Exit");
}
static gboolean prv_control_point_start_service(
dleyna_connector_id_t connection)
{
gboolean retval = TRUE;
uint i;
g_context.connection = connection;
for (i = 0; i < DLS_MANAGER_INTERFACE_INFO_MAX; i++)
g_context.dls_id[i] = g_context.connector->publish_object(
connection,
DLEYNA_SERVER_OBJECT,
TRUE,
g_manager_interfaces[i],
g_root_vtables + i);
if (g_context.dls_id[DLS_MANAGER_INTERFACE_MANAGER]) {
g_context.upnp = dls_upnp_new(connection,
dleyna_settings_port(g_context.settings),
g_server_vtables,
prv_found_media_server,
prv_lost_media_server,
NULL);
g_context.manager = dls_manager_new(connection,
dls_upnp_get_context_manager(
g_context.upnp));
prv_context_filter_init();
} else {
retval = FALSE;
}
return retval;
}
static void prv_control_point_stop_service(void)
{
uint i;
if (g_context.manager) {
dls_manager_delete(g_context.manager);
g_context.manager = NULL;
}
if (g_context.upnp) {
dls_upnp_unsubscribe(g_context.upnp);
dls_upnp_delete(g_context.upnp);
g_context.upnp = NULL;
}
if (g_context.connection) {
for (i = 0; i < DLS_MANAGER_INTERFACE_INFO_MAX; i++)
if (g_context.dls_id[i])
g_context.connector->unpublish_object(
g_context.connection,
g_context.dls_id[i]);
}
}
static void prv_control_point_initialize(const dleyna_connector_t *connector,
dleyna_task_processor_t *processor,
dleyna_settings_t *settings)
{
memset(&g_context, 0, sizeof(g_context));
g_context.connector = connector;
g_context.processor = processor;
g_context.settings = settings;
g_context.connector->set_client_lost_cb(prv_lost_client);
g_context.watchers = g_hash_table_new_full(g_str_hash, g_str_equal,
g_free, prv_unregister_client);
g_set_prgname(DLS_PRG_NAME);
}
static void prv_control_point_free(void)
{
if (g_context.watchers)
g_hash_table_unref(g_context.watchers);
}
static const gchar *prv_control_point_server_name(void)
{
return DLEYNA_SERVER_NAME;
}
static const gchar *prv_control_point_server_introspection(void)
{
return g_server_introspection;
}
static const gchar *prv_control_point_root_introspection(void)
{
return g_root_introspection;
}
static const gchar *prv_control_point_get_version(void)
{
return VERSION;
}
static const dleyna_control_point_t g_control_point = {
prv_control_point_initialize,
prv_control_point_free,
prv_control_point_server_name,
prv_control_point_server_introspection,
prv_control_point_root_introspection,
prv_control_point_start_service,
prv_control_point_stop_service,
prv_control_point_get_version
};
const dleyna_control_point_t *dleyna_control_point_get_server(void)
{
return &g_control_point;
}
|