Mercurial > pt1.oyama
comparison src/presentation.c @ 125:e413158cae13
Add ushare project files.
author | naoyan@johnstown.minaminoshima.org |
---|---|
date | Sun, 03 Oct 2010 11:35:19 +0900 |
parents | |
children | 2659ebefb192 |
comparison
equal
deleted
inserted
replaced
124:9c7bc6c0327e | 125:e413158cae13 |
---|---|
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> | |
22 | |
23 #if HAVE_LANGINFO_CODESET | |
24 # include <langinfo.h> | |
25 #endif | |
26 | |
27 #include "config.h" | |
28 #include "metadata.h" | |
29 #include "content.h" | |
30 #include "buffer.h" | |
31 #include "presentation.h" | |
32 #include "gettext.h" | |
33 #include "util_iconv.h" | |
34 | |
35 #define CGI_ACTION "action=" | |
36 #define CGI_ACTION_ADD "add" | |
37 #define CGI_ACTION_DEL "del" | |
38 #define CGI_ACTION_REFRESH "refresh" | |
39 #define CGI_PATH "path" | |
40 #define CGI_SHARE "share" | |
41 | |
42 int | |
43 process_cgi (struct ushare_t *ut, char *cgiargs) | |
44 { | |
45 char *action = NULL; | |
46 int refresh = 0; | |
47 | |
48 if (!ut || !cgiargs) | |
49 return -1; | |
50 | |
51 if (strncmp (cgiargs, CGI_ACTION, strlen (CGI_ACTION))) | |
52 return -1; | |
53 | |
54 action = cgiargs + strlen (CGI_ACTION); | |
55 | |
56 if (!strncmp (action, CGI_ACTION_ADD, strlen (CGI_ACTION_ADD))) | |
57 { | |
58 char *path = NULL; | |
59 path = action + strlen (CGI_ACTION_ADD) + 1; | |
60 | |
61 if (path && !strncmp (path, CGI_PATH"=", strlen (CGI_PATH) + 1)) | |
62 { | |
63 ut->contentlist = content_add (ut->contentlist, | |
64 path + strlen (CGI_PATH) + 1); | |
65 refresh = 1; | |
66 } | |
67 } | |
68 else if (!strncmp (action, CGI_ACTION_DEL, strlen (CGI_ACTION_DEL))) | |
69 { | |
70 char *shares,*share; | |
71 char *m_buffer = NULL, *buffer; | |
72 int num, shift=0; | |
73 | |
74 shares = strdup (action + strlen (CGI_ACTION_DEL) + 1); | |
75 m_buffer = (char*) malloc (strlen (shares) * sizeof (char)); | |
76 if (m_buffer) | |
77 { | |
78 buffer = m_buffer; | |
79 for (share = strtok_r (shares, "&", &buffer) ; share ; | |
80 share = strtok_r (NULL, "&", &buffer)) | |
81 { | |
82 if (sscanf (share, CGI_SHARE"[%d]=on", &num) < 0) | |
83 continue; | |
84 ut->contentlist = content_del (ut->contentlist, num - shift++); | |
85 } | |
86 free (m_buffer); | |
87 } | |
88 | |
89 refresh = 1; | |
90 free (shares); | |
91 } | |
92 else if (!strncmp (action, CGI_ACTION_REFRESH, strlen (CGI_ACTION_REFRESH))) | |
93 refresh = 1; | |
94 | |
95 if (refresh && ut->contentlist) | |
96 { | |
97 free_metadata_list (ut); | |
98 build_metadata_list (ut); | |
99 } | |
100 | |
101 if (ut->presentation) | |
102 buffer_free (ut->presentation); | |
103 ut->presentation = buffer_new (); | |
104 | |
105 buffer_append (ut->presentation, "<html>"); | |
106 buffer_append (ut->presentation, "<head>"); | |
107 buffer_appendf (ut->presentation, "<title>%s</title>", | |
108 _("uShare Information Page")); | |
109 buffer_append (ut->presentation, | |
110 "<meta http-equiv=\"pragma\" content=\"no-cache\"/>"); | |
111 buffer_append (ut->presentation, | |
112 "<meta http-equiv=\"expires\" content=\"1970-01-01\"/>"); | |
113 buffer_append (ut->presentation, | |
114 "<meta http-equiv=\"refresh\" content=\"0; URL=/web/ushare.html\"/>"); | |
115 buffer_append (ut->presentation, "</head>"); | |
116 buffer_append (ut->presentation, "</html>"); | |
117 | |
118 return 0; | |
119 } | |
120 | |
121 int | |
122 build_presentation_page (struct ushare_t *ut) | |
123 { | |
124 int i; | |
125 char *mycodeset = NULL; | |
126 | |
127 if (!ut) | |
128 return -1; | |
129 | |
130 if (ut->presentation) | |
131 buffer_free (ut->presentation); | |
132 ut->presentation = buffer_new (); | |
133 | |
134 #if HAVE_LANGINFO_CODESET | |
135 mycodeset = nl_langinfo (CODESET); | |
136 #endif | |
137 if (!mycodeset) | |
138 mycodeset = UTF8; | |
139 | |
140 buffer_append (ut->presentation, "<html>"); | |
141 buffer_append (ut->presentation, "<head>"); | |
142 buffer_appendf (ut->presentation, "<title>%s</title>", | |
143 _("uShare Information Page")); | |
144 buffer_appendf (ut->presentation, | |
145 "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\"/>", | |
146 mycodeset); | |
147 buffer_append (ut->presentation, | |
148 "<meta http-equiv=\"pragma\" content=\"no-cache\"/>"); | |
149 buffer_append (ut->presentation, | |
150 "<meta http-equiv=\"expires\" content=\"1970-01-01\"/>"); | |
151 buffer_append (ut->presentation, "</head>"); | |
152 buffer_append (ut->presentation, "<body>"); | |
153 buffer_append (ut->presentation, "<h1 align=\"center\">"); | |
154 buffer_appendf (ut->presentation, "<tt>%s</tt><br/>", | |
155 _("uShare UPnP A/V Media Server")); | |
156 buffer_append (ut->presentation, _("Information Page")); | |
157 buffer_append (ut->presentation, "</h1>"); | |
158 buffer_append (ut->presentation, "<br/>"); | |
159 | |
160 buffer_append (ut->presentation, "<center>"); | |
161 buffer_append (ut->presentation, "<tr width=\"500\">"); | |
162 buffer_appendf (ut->presentation, "<b>%s :</b> %s<br/>", | |
163 _("Version"), VERSION); | |
164 buffer_append (ut->presentation, "</tr>"); | |
165 buffer_appendf (ut->presentation, "<b>%s :</b> %s<br/>", | |
166 _("Device UDN"), ut->udn); | |
167 buffer_appendf (ut->presentation, "<b>%s :</b> %d<br/>", | |
168 _("Number of shared files and directories"), ut->nr_entries); | |
169 buffer_append (ut->presentation, "</center><br/>"); | |
170 | |
171 buffer_appendf (ut->presentation, | |
172 "<form method=\"get\" action=\"%s\">", USHARE_CGI); | |
173 buffer_appendf (ut->presentation, | |
174 "<input type=\"hidden\" name=\"action\" value=\"%s\"/>", | |
175 CGI_ACTION_DEL); | |
176 for (i = 0 ; i < ut->contentlist->count ; i++) | |
177 { | |
178 buffer_appendf (ut->presentation, "<b>%s #%d :</b>", _("Share"), i + 1); | |
179 buffer_appendf (ut->presentation, | |
180 "<input type=\"checkbox\" name=\""CGI_SHARE"[%d]\"/>", i); | |
181 buffer_appendf (ut->presentation, "%s<br/>", ut->contentlist->content[i]); | |
182 } | |
183 buffer_appendf (ut->presentation, | |
184 "<input type=\"submit\" value=\"%s\"/>", _("unShare!")); | |
185 buffer_append (ut->presentation, "</form>"); | |
186 buffer_append (ut->presentation, "<br/>"); | |
187 | |
188 buffer_appendf (ut->presentation, | |
189 "<form method=\"get\" action=\"%s\">", USHARE_CGI); | |
190 buffer_append (ut->presentation, _("Add a new share : ")); | |
191 buffer_appendf (ut->presentation, | |
192 "<input type=\"hidden\" name=\"action\" value=\"%s\"/>", | |
193 CGI_ACTION_ADD); | |
194 buffer_append (ut->presentation, "<input type=\"text\" name=\""CGI_PATH"\"/>"); | |
195 buffer_appendf (ut->presentation, | |
196 "<input type=\"submit\" value=\"%s\"/>", _("Share!")); | |
197 buffer_append (ut->presentation, "</form>"); | |
198 | |
199 buffer_append (ut->presentation, "<br/>"); | |
200 | |
201 buffer_appendf (ut->presentation, | |
202 "<form method=\"get\" action=\"%s\">", USHARE_CGI); | |
203 buffer_appendf (ut->presentation, | |
204 "<input type=\"hidden\" name=\"action\" value=\"%s\"/>", | |
205 CGI_ACTION_REFRESH); | |
206 buffer_appendf (ut->presentation, "<input type=\"submit\" value=\"%s\"/>", | |
207 _("Refresh Shares ...")); | |
208 buffer_append (ut->presentation, "</form>"); | |
209 buffer_append (ut->presentation, "</center>"); | |
210 | |
211 buffer_append (ut->presentation, "</body>"); | |
212 buffer_append (ut->presentation, "</html>"); | |
213 | |
214 return 0; | |
215 } |