125
|
1 /*
|
|
2 * cms.c : GeeXboX uShare Connection Management Service.
|
|
3 * Originally developped for the GeeXboX project.
|
|
4 * Parts of the code are originated from GMediaServer from Oskar Liljeblad.
|
|
5 * Copyright (C) 2005-2007 Benjamin Zores <ben@geexbox.org>
|
|
6 *
|
|
7 * This program is free software; you can redistribute it and/or modify
|
|
8 * it under the terms of the GNU General Public License as published by
|
|
9 * the Free Software Foundation; either version 2 of the License, or
|
|
10 * (at your option) any later version.
|
|
11 *
|
|
12 * This program is distributed in the hope that it will be useful,
|
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15 * GNU Library General Public License for more details.
|
|
16 *
|
|
17 * You should have received a copy of the GNU General Public License along
|
|
18 * with this program; if not, write to the Free Software Foundation,
|
|
19 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
20 */
|
|
21
|
|
22 #include <stdlib.h>
|
|
23 #include <upnp/upnp.h>
|
|
24 #include <upnp/upnptools.h>
|
|
25
|
|
26 #include "ushare.h"
|
|
27 #include "services.h"
|
|
28 #include "mime.h"
|
|
29
|
|
30 /* Represent the CMS GetProtocolInfo action. */
|
|
31 #define SERVICE_CMS_ACTION_PROT_INFO "GetProtocolInfo"
|
|
32
|
|
33 /* Represent the CMS GetCurrentConnectionIDs action. */
|
|
34 #define SERVICE_CMS_ACTION_CON_ID "GetCurrentConnectionIDs"
|
|
35
|
|
36 /* Represent the CMS GetCurrentConnectionInfo action. */
|
|
37 #define SERVICE_CMS_ACTION_CON_INFO "GetCurrentConnectionInfo"
|
|
38
|
|
39 /* Represent the CMS SOURCE argument. */
|
|
40 #define SERVICE_CMS_ARG_SOURCE "Source"
|
|
41
|
|
42 /* Represent the CMS SINK argument. */
|
|
43 #define SERVICE_CMS_ARG_SINK "Sink"
|
|
44
|
|
45 /* Represent the CMS ConnectionIDs argument. */
|
|
46 #define SERVICE_CMS_ARG_CONNECTION_IDS "ConnectionIDs"
|
|
47
|
|
48 /* Represent the CMS ConnectionID argument. */
|
|
49 #define SERVICE_CMS_ARG_CONNECTION_ID "ConnectionID"
|
|
50
|
|
51 /* Represent the CMS RcsID argument. */
|
|
52 #define SERVICE_CMS_ARG_RCS_ID "RcsID"
|
|
53
|
|
54 /* Represent the CMS AVTransportID argument. */
|
|
55 #define SERVICE_CMS_ARG_TRANSPORT_ID "AVTransportID"
|
|
56
|
|
57 /* Represent the CMS ProtocolInfo argument. */
|
|
58 #define SERVICE_CMS_ARG_PROT_INFO "ProtocolInfo"
|
|
59
|
|
60 /* Represent the CMS PeerConnectionManager argument. */
|
|
61 #define SERVICE_CMS_ARG_PEER_CON_MANAGER "PeerConnectionManager"
|
|
62
|
|
63 /* Represent the CMS PeerConnectionID argument. */
|
|
64 #define SERVICE_CMS_ARG_PEER_CON_ID "PeerConnectionID"
|
|
65
|
|
66 /* Represent the CMS Direction argument. */
|
|
67 #define SERVICE_CMS_ARG_DIRECTION "Direction"
|
|
68
|
|
69 /* Represent the CMS Status argument. */
|
|
70 #define SERVICE_CMS_ARG_STATUS "Status"
|
|
71
|
|
72 /* Represent the CMS default connection ID value. */
|
|
73 #define SERVICE_CMS_DEFAULT_CON_ID "0"
|
|
74
|
|
75 /* Represent the CMS unknown connection ID value. */
|
|
76 #define SERVICE_CMS_UNKNOW_ID "-1"
|
|
77
|
|
78 /* Represent the CMS Output value. */
|
|
79 #define SERVICE_CMS_OUTPUT "Output"
|
|
80
|
|
81 /* Represent the CMS Success Status. */
|
|
82 #define SERVICE_CMS_STATUS_OK "OK"
|
|
83
|
|
84 static bool
|
|
85 cms_get_protocol_info (struct action_event_t *event)
|
|
86 {
|
|
87 extern struct mime_type_t MIME_Type_List[];
|
|
88 struct mime_type_t *list;
|
|
89 char *respText = NULL, *respPtr;
|
|
90 size_t respLen = 0, len;
|
|
91
|
|
92 if (!event)
|
|
93 return false;
|
|
94
|
|
95 // calculating length of response
|
|
96 list = MIME_Type_List;
|
|
97 while (list->extension)
|
|
98 {
|
|
99 char *protocol = mime_get_protocol (list);
|
|
100 respLen += strlen (protocol) + 1;
|
|
101 free (protocol);
|
|
102 list++;
|
|
103 }
|
|
104
|
|
105 respText = (char*) malloc (respLen * sizeof (char));
|
|
106 if (!respText)
|
|
107 return event->status;
|
|
108
|
|
109 list = MIME_Type_List;
|
|
110 respPtr = respText;
|
|
111 while (list->extension)
|
|
112 {
|
|
113 char *protocol = mime_get_protocol (list);
|
|
114 len = strlen (protocol);
|
|
115 strncpy (respPtr, protocol, len);
|
|
116 free (protocol);
|
|
117 respPtr += len;
|
|
118 list++;
|
|
119 if (list->extension)
|
|
120 strcpy (respPtr++, ",");
|
|
121 }
|
|
122 *respPtr = '\0';
|
|
123
|
|
124 upnp_add_response (event, SERVICE_CMS_ARG_SOURCE, respText);
|
|
125 upnp_add_response (event, SERVICE_CMS_ARG_SINK, "");
|
|
126
|
|
127 free (respText);
|
|
128 return event->status;
|
|
129 }
|
|
130
|
|
131 static bool
|
|
132 cms_get_current_connection_ids (struct action_event_t *event)
|
|
133 {
|
|
134 if (!event)
|
|
135 return false;
|
|
136
|
|
137 upnp_add_response (event, SERVICE_CMS_ARG_CONNECTION_IDS, "");
|
|
138
|
|
139 return event->status;
|
|
140 }
|
|
141
|
|
142 static bool
|
|
143 cms_get_current_connection_info (struct action_event_t *event)
|
|
144 {
|
|
145 extern struct mime_type_t MIME_Type_List[];
|
|
146 struct mime_type_t *list = MIME_Type_List;
|
|
147
|
|
148 if (!event)
|
|
149 return false;
|
|
150
|
|
151 upnp_add_response (event, SERVICE_CMS_ARG_CONNECTION_ID,
|
|
152 SERVICE_CMS_DEFAULT_CON_ID);
|
|
153 upnp_add_response (event, SERVICE_CMS_ARG_RCS_ID, SERVICE_CMS_UNKNOW_ID);
|
|
154 upnp_add_response (event, SERVICE_CMS_ARG_TRANSPORT_ID,
|
|
155 SERVICE_CMS_UNKNOW_ID);
|
|
156
|
|
157 while (list->extension)
|
|
158 {
|
|
159 char *protocol = mime_get_protocol (list);
|
|
160 upnp_add_response (event, SERVICE_CMS_ARG_PROT_INFO, protocol);
|
|
161 free (protocol);
|
|
162 list++;
|
|
163 }
|
|
164
|
|
165 upnp_add_response (event, SERVICE_CMS_ARG_PEER_CON_MANAGER, "");
|
|
166 upnp_add_response (event, SERVICE_CMS_ARG_PEER_CON_ID,
|
|
167 SERVICE_CMS_UNKNOW_ID);
|
|
168 upnp_add_response (event, SERVICE_CMS_ARG_DIRECTION, SERVICE_CMS_OUTPUT);
|
|
169 upnp_add_response (event, SERVICE_CMS_ARG_STATUS, SERVICE_CMS_STATUS_OK);
|
|
170
|
|
171 return event->status;
|
|
172 }
|
|
173
|
|
174 /* List of UPnP ConnectionManager Service actions */
|
|
175 struct service_action_t cms_service_actions[] = {
|
|
176 { SERVICE_CMS_ACTION_PROT_INFO, cms_get_protocol_info },
|
|
177 { SERVICE_CMS_ACTION_CON_ID, cms_get_current_connection_ids },
|
|
178 { SERVICE_CMS_ACTION_CON_INFO, cms_get_current_connection_info },
|
|
179 { NULL, NULL }
|
|
180 };
|