3 * Copyright (c) 2007 acmesystems.it - john@acmesystems.it
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA
19 * Feedback, Bugs... info@acmesystems.it
26 #include <sys/types.h>
27 #include <sys/socket.h>
34 #define SOCKET_PATH "/tmp/foxmp3"
36 void print_http_header(){
37 printf("Content-type: text/html\n\n");
40 int read_parameter(char *name
, char *value
, int maxlen
){
42 char *query_string
= getenv("QUERY_STRING");
46 pos1
= strstr(query_string
, name
);
48 pos1
+= strlen(name
) + 1;
49 pos2
= strstr(pos1
, "&");
53 if(strlen(pos1
) >= maxlen
){
64 int issue_command(unsigned char *str
){
66 struct sockaddr_un remote
;
68 if ((s
= socket(AF_UNIX
, SOCK_STREAM
, 0)) == -1) {
71 remote
.sun_family
= AF_UNIX
;
72 strcpy(remote
.sun_path
, SOCKET_PATH
);
73 len
= strlen(remote
.sun_path
) + sizeof(remote
.sun_family
);
74 if (connect(s
, (struct sockaddr
*)&remote
, len
) == -1) {
77 if (send(s
, str
, strlen(str
), 0) == -1) {
80 unsigned char loop
= 1;
82 if ((t
=recv(s
, str
, 2048, 0)) > 0) {
84 if((strstr(str
, "OK\n")) || (strstr(str
, "ERROR\n"))){
96 unsigned char param
[128];
97 unsigned char cmd
[256];
100 if(read_parameter("vol", param
, 128)){
103 sprintf(cmd
, "VOLUME %d", i
);
105 if(read_parameter("bass", param
, 128)){
107 sprintf(cmd
, "BASS %d", i
);
109 if(read_parameter("start", param
, 128)){
110 sprintf(cmd
, "START");
112 if(read_parameter("stop", param
, 128)){
113 sprintf(cmd
, "STOP");
115 if(read_parameter("next", param
, 128)){
116 sprintf(cmd
, "NEXT");
118 if(read_parameter("back", param
, 128)){
119 sprintf(cmd
, "BACK");
126 void print_html_remote(){
128 gethostname(name
, 128);
129 printf("<html><head><title>foxmp3 - %s - remote</title><link rel=\"stylesheet\" href=\"../local/stylesheet.css\" type=\"text/css\" /><script src=\"../local/json.js\" type=\"text/javascript\"></script></head><body onload=\"alpmp3_setup();\">");
130 printf("<center><p id=alpmp3_remote>");
131 printf("<table width=50%%>");
132 printf("<tr class=cellhead><th colspan=3 id=cell align=center>FOXMP3 - %s </td></tr>", name
);
133 printf("<tr class=cellone><td>Action</td><td colspan=2 id=alpmp3_state>0</td></tr>");
134 printf("<tr class=celltwo><td>Filename</td><td colspan=2 id=alpmp3_filename>0</td></tr>");
135 printf("<tr class=cellone><td>Playtime</td><td colspan=2 id=alpmp3_playtime>0</td></tr>");
136 printf("<tr class=celltwo><td>Volume</td><td id=alpmp3_volume>0</td><td><a href=\"#\" onclick=\"javascript:alpmp3_remote('volup');\">Up</a> <a href=\"#\" onclick=\"javascript:alpmp3_remote('voldown')\">Down</a></td></tr>");
137 printf("<tr class=cellone><td width=20%%>Bass</td><td id=alpmp3_bass>0</td><td><a href=\"#\" onclick=\"javascript:alpmp3_remote('bassup');\" class=browse>Up</a> <a href=\"#\" onclick=\"javascript:alpmp3_remote('bassdown')\" class=browse>Down</a></td></tr>");
138 printf("<tr class=cellhead><th colspan=3 id=cell align=center><a href=\"#\" onclick=\"javascript:alpmp3_remote('start');\">Start</a> <a href=\"#\" onclick=\"javascript:alpmp3_remote('stop');\">Stop</a> <a href=\"#\" onclick=\"javascript:alpmp3_remote('back');\">Back</a> <a href=\"#\" onclick=\"javascript:alpmp3_remote('next');\">Next</a> </td></tr>");
140 printf("</p></center>");
141 printf("</body></html>");
146 void print_json_info(){
147 unsigned char str
[2048];
148 sprintf(str
, "STATE");
149 if(issue_command(str
) == 0){
154 unsigned char filename
[1024];
155 unsigned char *p1
, *p2
;
157 memset(filename
, 0, 1024);
160 p2
= strstr(p1
, "\n");
164 // printf("parsing %s\n", p1);
165 if(strncmp(p1
, "VOLUME", strlen("VOLUME")) == 0){
166 volume
= atoi(&p1
[strlen("VOLUME") + 1]);
169 volume
= 120 - volume
;
171 //printf("vol = %d\n", volume);
172 } else if(strncmp(p1
, "BASS", strlen("BASS")) == 0){
173 bass
= atoi(&p1
[strlen("BASS") + 1]);
174 //printf("bass = %d\n", bass);
175 } else if(strncmp(p1
, "PLAYTIME", strlen("PLAYTIME")) == 0){
176 playtime
= atoi(&p1
[strlen("PLAYTIME") + 1]);
177 //printf("playtime = %d\n", playtime);
178 } else if(strncmp(p1
, "STATE", strlen("STATE")) == 0){
179 if(strstr(p1
, "MP3_STATE_IDLE")){
181 } else if(strstr(p1
, "MP3_STATE_FILE")){
183 } else if(strstr(p1
, "MP3_STATE_STREAM")){
186 //printf("state = %d\n", state);
187 } else if(strncmp(p1
, "STREAM", strlen("STREAM")) == 0){
188 strcpy(filename
, &p1
[strlen("STREAM") + 1]);
189 //printf("filename = %s\n", filename);
190 } else if(strncmp(p1
, "FILE", strlen("FILE")) == 0){
191 strcpy(filename
, &p1
[strlen("FILE") + 1]);
192 //printf("filename = %s\n", filename);
201 struct json_object
*alpmp3
= json_object_new_object();
202 json_object_object_add(alpmp3
, "state", json_object_new_int(state
));
205 json_object_object_add(alpmp3
, "type", json_object_new_string("file"));
208 json_object_object_add(alpmp3
, "type", json_object_new_string("stream"));
211 json_object_object_add(alpmp3
, "type", json_object_new_string("idle"));
214 json_object_object_add(alpmp3
, "volume", json_object_new_int(volume
));
215 json_object_object_add(alpmp3
, "bass", json_object_new_int(bass
));
216 json_object_object_add(alpmp3
, "playtime", json_object_new_int(playtime
));
217 json_object_object_add(alpmp3
, "filename", json_object_new_string(filename
));
218 struct json_object
*jo
= json_object_new_object();
219 json_object_object_add(jo
, "alpmp3", alpmp3
);
220 printf("\n%s\n", json_object_to_json_string(jo
));
224 int main(int argc
, char **argv
){
227 if(strstr(argv
[0], "mp3_remote.cgi")){
229 } else if(strstr(argv
[0], "mp3_json.cgi")){
231 } else if(strstr(argv
[0], "mp3_cmd.cgi")){
234 printf("Unknown command");
This page took 0.066385 seconds and 5 git commands to generate.