Mercurial > pt1.oyama
annotate src/services.c @ 152:30e91361506a
EXPERIMENTAL: Enable change phisical channel by DLNA.(ISDB-T only)
author | Naoya OYAMA <naoya.oyama@gmail.com> |
---|---|
date | Sun, 02 Sep 2012 01:59:27 +0900 |
parents | 2a9ac5ce2c7e |
children |
rev | line source |
---|---|
125 | 1 /* |
2 * services.c : GeeXboX uShare UPnP services handler. | |
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> | |
136
2a9ac5ce2c7e
Remove internal libdlna and libupnp.(using OS package by default)
Naoya OYAMA <naoya.oyama@gmail.com>
parents:
125
diff
changeset
|
23 #include <upnp.h> |
2a9ac5ce2c7e
Remove internal libdlna and libupnp.(using OS package by default)
Naoya OYAMA <naoya.oyama@gmail.com>
parents:
125
diff
changeset
|
24 #include <upnptools.h> |
125 | 25 |
26 #include "ushare.h" | |
27 #include "services.h" | |
28 #include "cms.h" | |
29 #include "cds.h" | |
30 #include "msr.h" | |
31 #include "trace.h" | |
32 | |
33 /* Represent the ObjectID argument. */ | |
34 #define ARG_OBJECT_ID "ObjectID" | |
35 | |
36 /* Represent the ContainerID argument. */ | |
37 #define ARG_CONTAINER_ID "ContainerID" | |
38 | |
39 extern struct service_action_t cds_service_actions[]; | |
40 extern struct service_action_t cms_service_actions[]; | |
41 extern struct service_action_t msr_service_actions[]; | |
42 | |
43 static struct service_t services[] = { | |
44 { | |
45 CDS_SERVICE_ID, | |
46 CDS_SERVICE_TYPE, | |
47 cds_service_actions | |
48 }, | |
49 { | |
50 CMS_SERVICE_ID, | |
51 CMS_SERVICE_TYPE, | |
52 cms_service_actions | |
53 }, | |
54 { | |
55 MSR_SERVICE_ID, | |
56 MSR_SERVICE_TYPE, | |
57 msr_service_actions | |
58 }, | |
59 { NULL, NULL, NULL } | |
60 }; | |
61 | |
62 bool | |
63 find_service_action (struct Upnp_Action_Request *request, | |
64 struct service_t **service, | |
65 struct service_action_t **action) | |
66 { | |
67 int c, d; | |
68 | |
69 *service = NULL; | |
70 *action = NULL; | |
71 | |
72 if (!request || !request->ActionName) | |
73 return false; | |
74 | |
75 for (c = 0; services[c].id != NULL; c++) | |
76 if (!strcmp (services[c].id, request->ServiceID)) | |
77 { | |
78 *service = &services[c]; | |
79 for (d = 0; services[c].actions[d].name; d++) | |
80 { | |
81 if (!strcmp (services[c].actions[d].name, request->ActionName)) | |
82 { | |
83 *action = &services[c].actions[d]; | |
84 return true; | |
85 } | |
86 } | |
87 return false; | |
88 } | |
89 | |
90 return false; | |
91 } | |
92 | |
93 bool | |
94 upnp_add_response (struct action_event_t *event, char *key, const char *value) | |
95 { | |
96 char *val; | |
97 int res; | |
98 | |
99 if (!event || !event->status || !key || !value) | |
100 return false; | |
101 | |
102 val = strdup (value); | |
103 if (!val) | |
104 return false; | |
105 | |
106 res = UpnpAddToActionResponse (&event->request->ActionResult, | |
107 event->request->ActionName, | |
108 event->service->type, key, val); | |
109 | |
110 if (res != UPNP_E_SUCCESS) | |
111 { | |
112 free (val); | |
113 return false; | |
114 } | |
115 | |
116 free (val); | |
117 return true; | |
118 } | |
119 | |
120 char * | |
121 upnp_get_string (struct Upnp_Action_Request *request, const char *key) | |
122 { | |
123 IXML_Node *node = NULL; | |
124 | |
125 if (!request || !request->ActionRequest || !key) | |
126 return NULL; | |
127 | |
128 node = (IXML_Node *) request->ActionRequest; | |
129 if (!node) | |
130 { | |
131 log_verbose ("Invalid action request document\n"); | |
132 return NULL; | |
133 } | |
134 | |
135 node = ixmlNode_getFirstChild (node); | |
136 if (!node) | |
137 { | |
138 log_verbose ("Invalid action request document\n"); | |
139 return NULL; | |
140 } | |
141 | |
142 node = ixmlNode_getFirstChild (node); | |
143 for (; node; node = ixmlNode_getNextSibling (node)) | |
144 if (!strcmp (ixmlNode_getNodeName (node), key)) | |
145 { | |
146 node = ixmlNode_getFirstChild (node); | |
147 if (!node) | |
148 return strdup (""); | |
149 return strdup (ixmlNode_getNodeValue (node)); | |
150 } | |
151 | |
152 log_verbose ("Missing action request argument (%s)\n", key); | |
153 | |
154 return NULL; | |
155 } | |
156 | |
157 int | |
158 upnp_get_ui4 (struct Upnp_Action_Request *request, const char *key) | |
159 { | |
160 char *value; | |
161 int val; | |
162 | |
163 if (!request || !key) | |
164 return 0; | |
165 | |
166 value = upnp_get_string (request, key); | |
167 if (!value && !strcmp (key, ARG_OBJECT_ID)) | |
168 value = upnp_get_string (request, ARG_CONTAINER_ID); | |
169 | |
170 if (!value) | |
171 return 0; | |
172 | |
173 val = atoi (value); | |
174 free (value); | |
175 | |
176 return val; | |
177 } |