125
|
1 /*
|
|
2 * presentation.c : GeeXboX uShare UPnP Presentation Page.
|
|
3 * Originally developped for the GeeXboX project.
|
|
4 * Copyright (C) 2005-2007 Benjamin Zores <ben@geexbox.org>
|
|
5 *
|
|
6 * This program is free software; you can redistribute it and/or modify
|
|
7 * it under the terms of the GNU General Public License as published by
|
|
8 * the Free Software Foundation; either version 2 of the License, or
|
|
9 * (at your option) any later version.
|
|
10 *
|
|
11 * This program is distributed in the hope that it will be useful,
|
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 * GNU Library General Public License for more details.
|
|
15 *
|
|
16 * You should have received a copy of the GNU General Public License along
|
|
17 * with this program; if not, write to the Free Software Foundation,
|
|
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
19 */
|
|
20
|
|
21 #include <stdlib.h>
|
180
|
22 #include <string.h>
|
125
|
23
|
|
24 #if HAVE_LANGINFO_CODESET
|
|
25 # include <langinfo.h>
|
|
26 #endif
|
|
27
|
|
28 #include "config.h"
|
|
29 #include "metadata.h"
|
|
30 #include "content.h"
|
|
31 #include "buffer.h"
|
|
32 #include "presentation.h"
|
|
33 #include "gettext.h"
|
|
34 #include "util_iconv.h"
|
|
35
|
|
36 #define CGI_ACTION "action="
|
|
37 #define CGI_ACTION_ADD "add"
|
|
38 #define CGI_ACTION_DEL "del"
|
|
39 #define CGI_ACTION_REFRESH "refresh"
|
|
40 #define CGI_PATH "path"
|
|
41 #define CGI_SHARE "share"
|
|
42
|
|
43 int
|
|
44 process_cgi (struct ushare_t *ut, char *cgiargs)
|
|
45 {
|
|
46 char *action = NULL;
|
|
47 int refresh = 0;
|
|
48
|
|
49 if (!ut || !cgiargs)
|
|
50 return -1;
|
|
51
|
|
52 if (strncmp (cgiargs, CGI_ACTION, strlen (CGI_ACTION)))
|
|
53 return -1;
|
|
54
|
|
55 action = cgiargs + strlen (CGI_ACTION);
|
|
56
|
|
57 if (!strncmp (action, CGI_ACTION_ADD, strlen (CGI_ACTION_ADD)))
|
|
58 {
|
|
59 char *path = NULL;
|
|
60 path = action + strlen (CGI_ACTION_ADD) + 1;
|
|
61
|
|
62 if (path && !strncmp (path, CGI_PATH"=", strlen (CGI_PATH) + 1))
|
|
63 {
|
|
64 ut->contentlist = content_add (ut->contentlist,
|
|
65 path + strlen (CGI_PATH) + 1);
|
|
66 refresh = 1;
|
|
67 }
|
|
68 }
|
|
69 else if (!strncmp (action, CGI_ACTION_DEL, strlen (CGI_ACTION_DEL)))
|
|
70 {
|
|
71 char *shares,*share;
|
|
72 char *m_buffer = NULL, *buffer;
|
|
73 int num, shift=0;
|
|
74
|
|
75 shares = strdup (action + strlen (CGI_ACTION_DEL) + 1);
|
|
76 m_buffer = (char*) malloc (strlen (shares) * sizeof (char));
|
|
77 if (m_buffer)
|
|
78 {
|
|
79 buffer = m_buffer;
|
|
80 for (share = strtok_r (shares, "&", &buffer) ; share ;
|
|
81 share = strtok_r (NULL, "&", &buffer))
|
|
82 {
|
|
83 if (sscanf (share, CGI_SHARE"[%d]=on", &num) < 0)
|
|
84 continue;
|
|
85 ut->contentlist = content_del (ut->contentlist, num - shift++);
|
|
86 }
|
|
87 free (m_buffer);
|
|
88 }
|
|
89
|
|
90 refresh = 1;
|
|
91 free (shares);
|
|
92 }
|
|
93 else if (!strncmp (action, CGI_ACTION_REFRESH, strlen (CGI_ACTION_REFRESH)))
|
|
94 refresh = 1;
|
|
95
|
|
96 if (refresh && ut->contentlist)
|
|
97 {
|
|
98 free_metadata_list (ut);
|
|
99 build_metadata_list (ut);
|
|
100 }
|
|
101
|
|
102 if (ut->presentation)
|
|
103 buffer_free (ut->presentation);
|
|
104 ut->presentation = buffer_new ();
|
|
105
|
|
106 buffer_append (ut->presentation, "<html>");
|
|
107 buffer_append (ut->presentation, "<head>");
|
|
108 buffer_appendf (ut->presentation, "<title>%s</title>",
|
|
109 _("uShare Information Page"));
|
|
110 buffer_append (ut->presentation,
|
|
111 "<meta http-equiv=\"pragma\" content=\"no-cache\"/>");
|
|
112 buffer_append (ut->presentation,
|
|
113 "<meta http-equiv=\"expires\" content=\"1970-01-01\"/>");
|
|
114 buffer_append (ut->presentation,
|
|
115 "<meta http-equiv=\"refresh\" content=\"0; URL=/web/ushare.html\"/>");
|
|
116 buffer_append (ut->presentation, "</head>");
|
|
117 buffer_append (ut->presentation, "</html>");
|
|
118
|
|
119 return 0;
|
|
120 }
|
|
121
|
|
122 int
|
|
123 build_presentation_page (struct ushare_t *ut)
|
|
124 {
|
|
125 int i;
|
|
126 char *mycodeset = NULL;
|
|
127
|
|
128 if (!ut)
|
|
129 return -1;
|
|
130
|
|
131 if (ut->presentation)
|
|
132 buffer_free (ut->presentation);
|
|
133 ut->presentation = buffer_new ();
|
|
134
|
|
135 #if HAVE_LANGINFO_CODESET
|
|
136 mycodeset = nl_langinfo (CODESET);
|
|
137 #endif
|
|
138 if (!mycodeset)
|
|
139 mycodeset = UTF8;
|
|
140
|
|
141 buffer_append (ut->presentation, "<html>");
|
|
142 buffer_append (ut->presentation, "<head>");
|
|
143 buffer_appendf (ut->presentation, "<title>%s</title>",
|
|
144 _("uShare Information Page"));
|
|
145 buffer_appendf (ut->presentation,
|
|
146 "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\"/>",
|
|
147 mycodeset);
|
|
148 buffer_append (ut->presentation,
|
|
149 "<meta http-equiv=\"pragma\" content=\"no-cache\"/>");
|
|
150 buffer_append (ut->presentation,
|
|
151 "<meta http-equiv=\"expires\" content=\"1970-01-01\"/>");
|
|
152 buffer_append (ut->presentation, "</head>");
|
|
153 buffer_append (ut->presentation, "<body>");
|
|
154 buffer_append (ut->presentation, "<h1 align=\"center\">");
|
|
155 buffer_appendf (ut->presentation, "<tt>%s</tt><br/>",
|
|
156 _("uShare UPnP A/V Media Server"));
|
|
157 buffer_append (ut->presentation, _("Information Page"));
|
|
158 buffer_append (ut->presentation, "</h1>");
|
|
159 buffer_append (ut->presentation, "<br/>");
|
|
160
|
|
161 buffer_append (ut->presentation, "<center>");
|
|
162 buffer_append (ut->presentation, "<tr width=\"500\">");
|
|
163 buffer_appendf (ut->presentation, "<b>%s :</b> %s<br/>",
|
|
164 _("Version"), VERSION);
|
|
165 buffer_append (ut->presentation, "</tr>");
|
|
166 buffer_appendf (ut->presentation, "<b>%s :</b> %s<br/>",
|
|
167 _("Device UDN"), ut->udn);
|
|
168 buffer_appendf (ut->presentation, "<b>%s :</b> %d<br/>",
|
|
169 _("Number of shared files and directories"), ut->nr_entries);
|
|
170 buffer_append (ut->presentation, "</center><br/>");
|
|
171
|
|
172 buffer_appendf (ut->presentation,
|
|
173 "<form method=\"get\" action=\"%s\">", USHARE_CGI);
|
|
174 buffer_appendf (ut->presentation,
|
|
175 "<input type=\"hidden\" name=\"action\" value=\"%s\"/>",
|
|
176 CGI_ACTION_DEL);
|
|
177 for (i = 0 ; i < ut->contentlist->count ; i++)
|
|
178 {
|
|
179 buffer_appendf (ut->presentation, "<b>%s #%d :</b>", _("Share"), i + 1);
|
|
180 buffer_appendf (ut->presentation,
|
|
181 "<input type=\"checkbox\" name=\""CGI_SHARE"[%d]\"/>", i);
|
|
182 buffer_appendf (ut->presentation, "%s<br/>", ut->contentlist->content[i]);
|
|
183 }
|
|
184 buffer_appendf (ut->presentation,
|
|
185 "<input type=\"submit\" value=\"%s\"/>", _("unShare!"));
|
|
186 buffer_append (ut->presentation, "</form>");
|
|
187 buffer_append (ut->presentation, "<br/>");
|
|
188
|
|
189 buffer_appendf (ut->presentation,
|
|
190 "<form method=\"get\" action=\"%s\">", USHARE_CGI);
|
|
191 buffer_append (ut->presentation, _("Add a new share : "));
|
|
192 buffer_appendf (ut->presentation,
|
|
193 "<input type=\"hidden\" name=\"action\" value=\"%s\"/>",
|
|
194 CGI_ACTION_ADD);
|
|
195 buffer_append (ut->presentation, "<input type=\"text\" name=\""CGI_PATH"\"/>");
|
|
196 buffer_appendf (ut->presentation,
|
|
197 "<input type=\"submit\" value=\"%s\"/>", _("Share!"));
|
|
198 buffer_append (ut->presentation, "</form>");
|
|
199
|
|
200 buffer_append (ut->presentation, "<br/>");
|
|
201
|
|
202 buffer_appendf (ut->presentation,
|
|
203 "<form method=\"get\" action=\"%s\">", USHARE_CGI);
|
|
204 buffer_appendf (ut->presentation,
|
|
205 "<input type=\"hidden\" name=\"action\" value=\"%s\"/>",
|
|
206 CGI_ACTION_REFRESH);
|
|
207 buffer_appendf (ut->presentation, "<input type=\"submit\" value=\"%s\"/>",
|
|
208 _("Refresh Shares ..."));
|
|
209 buffer_append (ut->presentation, "</form>");
|
|
210 buffer_append (ut->presentation, "</center>");
|
|
211
|
|
212 buffer_append (ut->presentation, "</body>");
|
|
213 buffer_append (ut->presentation, "</html>");
|
|
214
|
|
215 return 0;
|
|
216 }
|